package org.lcc.mapper;

import org.apache.ibatis.annotations.*;
import org.lcc.model.entity.Message;

import java.util.List;

@Mapper
public interface MessageMapper {

    @Insert("INSERT INTO message(sender_id, receiver_id, content, message_type, send_time, read_status) " +
            "VALUES(#{senderId}, #{receiverId}, #{content}, #{messageType}, #{sendTime}, #{readStatus})")
    @Options(useGeneratedKeys = true, keyProperty = "messageId")
    int insert(Message message);

    @Select("SELECT * FROM message WHERE receiver_id = #{userId} AND read_status = 0 ORDER BY send_time DESC")
    List<Message> selectUnreadByUserId(String userId);

    @Update("UPDATE message SET read_status = #{status} WHERE message_id = #{messageId}")
    int updateReadStatus(Integer messageId, boolean status);

    @Select("SELECT * FROM message WHERE receiver_id = #{userId} ORDER BY send_time DESC LIMIT #{offset}, #{size}")
    List<Message> selectByUserId(String userId, int offset, int size);
    @Select("SELECT school_number FROM student_class_link WHERE class_id = #{classId}")
    List<String> getStudentIdsByClassId(Integer classId);
}

